using System;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.Base.Exceptions;
using Habanero.BO.ClassDefinition;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for UIColumnLayout objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for UIColumnLayout.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestUIColumnLayout
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [Test]
        public void Test_ToString_WhenUITabNull_ShouldRetOrdinalPosition()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout formColumn = new UIColumnLayout();
            var actualOrdinalPosition = TestUtilsShared.GetRandomInt();
            formColumn.OrdinalPosition = actualOrdinalPosition;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(formColumn.OrdinalPosition);
            Assert.IsNull(formColumn.UITab);
            //---------------Execute Test ----------------------
            var actualToString = formColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("_" + actualOrdinalPosition, actualToString);
        }
        [Test]
        public void Test_ToString_WhenUITabNotNull_ShouldRetTabPlusOrdinalPosition()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout formColumn = TestUtilsUIColumnLayout.CreateUnsavedValidUIColumnLayout();
            var actualOrdinalPosition = TestUtilsShared.GetRandomInt();
            formColumn.OrdinalPosition = actualOrdinalPosition;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(formColumn.OrdinalPosition);
            Assert.IsNotNull(formColumn.UITab);
            //---------------Execute Test ----------------------
            var actualToString = formColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(formColumn.UITab.Name + "_" + actualOrdinalPosition, actualToString);
        }

        [Test]
        public void Test_IUIFormColumn_Width_Get()
        {
            //---------------Set up test pack-------------------
            IUIFormColumn formColumn = new UIColumnLayout();
            int width = TestUtilsShared.GetRandomInt();
            ((UIColumnLayout)formColumn).Width = width;
            //---------------Assert Precondition----------------
            Assert.Greater(width, 0);
            //---------------Execute Test ----------------------
            int returnedWidth = formColumn.Width;

            //---------------Test Result -----------------------
            Assert.AreEqual(width, returnedWidth); ;
        }

        [Test]
        public void Test_IUIFormColumn_Width_Set()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout columnLayout = new UIColumnLayout();
            IUIFormColumn formColumn = columnLayout;
            int width = TestUtilsShared.GetRandomInt();
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(columnLayout.Width, width);
            //---------------Execute Test ----------------------
            formColumn.Width = width;

            //---------------Test Result -----------------------
            Assert.AreEqual(width, columnLayout.Width); ;
        }

        [Test]
        public void Test_IUIFormColumn_UIFormTab_Get()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout columnLayout = TestUtilsShared.CreateUnsavedValidUIColumnLayoutInfo();
            UITab uiTab = columnLayout.UITab;
            IUIFormColumn formColumn = columnLayout;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiTab);
            //---------------Execute Test ----------------------
            IUIFormTab formTab = formColumn.UIFormTab;

            //---------------Test Result -----------------------
            Assert.AreSame(uiTab, formTab); ;
        }


        [Test]
        public void Test_IUIFormColumn_UIFormTab_Set()
        {
            //---------------Set up test pack-------------------
            IUIFormColumn formColumn = new UIColumnLayout();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                formColumn.UIFormTab = new UIFormTab();
                Assert.Fail("Expected to throw an NotImplementedException");
            }
                //---------------Test Result -----------------------
            catch (NotImplementedException ex)
            {
                StringAssert.Contains("Please set this via the UITab relationship.", ex.Message);
            }
        }

        [Test]
        public void Test_IUIFormColumn_Contains_ReturnsTrue()
        {
            //---------------Set up test pack-------------------
            UIField uiField = TestUtilsShared.CreateUnsavedValidUIField();
            UIColumnLayout columnLayout = uiField.UIColumnLayout;
            IUIFormColumn formColumn = columnLayout;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(columnLayout);
            Assert.IsTrue(columnLayout.UIFields.Contains(uiField));
            //---------------Execute Test ----------------------
            bool contains = formColumn.Contains(uiField);

            //---------------Test Result -----------------------
            Assert.IsTrue(contains); ;
        }


        [Test]
        public void Test_IUIFormColumn_Contains_ReturnsFalse()
        {
            //---------------Set up test pack-------------------
            UIField uiField = TestUtilsShared.CreateUnsavedValidUIField();
            UIColumnLayout columnLayout = uiField.UIColumnLayout;
            IUIFormColumn formColumn = columnLayout;
            UIField field = new UIField();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(columnLayout);
            Assert.IsFalse(columnLayout.UIFields.Contains(field));
            //---------------Execute Test ----------------------
            bool contains = formColumn.Contains(field);

            //---------------Test Result -----------------------
            Assert.IsFalse(contains); 
        }

        [Test]
        public void Test_ICollection_Count()
        {
            //---------------Set up test pack-------------------
            UIField uiField = TestUtilsShared.CreateUnsavedValidUIField();
            UIColumnLayout columnLayout = uiField.UIColumnLayout;
            IUIFormColumn formColumn = columnLayout;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(columnLayout);
            Assert.AreEqual(1, columnLayout.UIFields.Count);
            //---------------Execute Test ----------------------
            int count = formColumn.Count;

            //---------------Test Result -----------------------
            Assert.AreEqual(columnLayout.UIFields.Count, count); 
        }

        [Test]
        public void Test_IUIFormColumn_this()
        {
            //---------------Set up test pack-------------------
            UIField uiField1= TestUtilsShared.CreateUnsavedValidUIField();
            UIColumnLayout columnLayout = uiField1.UIColumnLayout;
            UIField uiField2 = TestUtilsShared.CreateUnsavedValidUIField(columnLayout);
            IUIFormColumn formColumn = columnLayout;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, columnLayout.UIFields.Count);
            //---------------Execute Test ----------------------
            IUIFormField formField = formColumn[1];
            //---------------Test Result -----------------------
            Assert.IsNotNull(formField);
            Assert.AreSame(uiField2, formField);
        }

        [Test]
        public void Test_CreateNewUIFields_ShouldSetOrdinals()
        {
            //---------------Set up test pack-------------------
            UIColumnLayout uiColumnLayout = new UIColumnLayout();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            UIField uiField1 = uiColumnLayout.UIFields.CreateBusinessObject();
            UIField uiField2 = uiColumnLayout.UIFields.CreateBusinessObject();
            UIField uiField3 = uiColumnLayout.UIFields.CreateBusinessObject();
            UIField uiField4 = uiColumnLayout.UIFields.CreateBusinessObject();
            UIField uiField5 = uiColumnLayout.UIFields.CreateBusinessObject();
            UIField uiField6 = uiColumnLayout.UIFields.CreateBusinessObject();
            //---------------Test Result -----------------------
            TestUtilsShared.AssertItemsAreInOrder(uiField1, uiField2, uiField3, uiField4, uiField5, uiField6);
        }
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            UITab view = new UITab();
            UIColumnLayout formInfo = new UIColumnLayout();
            view.UIColumnLayouts.Add(formInfo);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelElement)formInfo).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(view, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelElement prop = new UIColumnLayout();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                prop.Parent = new UITab();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the UIColumnLayout by setting the related UITab object", exceptionThrown.Message);
        }
 
    }
}